<template>
    <view class="code-box">
		<comHeader :config="navConfig" />
		<view class="title">获取验证码</view>
		<view class="YZM">
			<view>
				<input type="text" v-model="name" placeholder="请输入短信验证码" placeholder-style="color:#999999;" class="order-input">
				<view class="line"></view>
			</view>
			<view class="mintuesBox">
				<button 
				class="minuts"
				size="mini"
				@tap="TimeBtn" 
				:disabled="disabled"
				:class="[disabled ? '':'blueMintues']">{{countdown}}<text v-show="timeStatus">秒后重发</text></button>
			</view>
		</view>
		<view class="receive" @tap="modalTap">收不到验证码</view>
		
		<navigator url="../../../components/PayCommon" class="btn" @tap="toast1Tap">
			<text>确认</text>
		</navigator>
    </view>
</template>

<script>
	export default {
		
	    name: 'uiOneInput',
	    props: {
	        // 4/6
	        maxlength: {
	            type: Number,
	            default: 4
	        },
	        isPwd: {
	            type: Boolean,
	            default: false
	        },
	        // middle-middle line, bottom-bottom line, box-square box
	        type: {
	            type: String,
	            default: "bottom"
	        }
	    },
	    watch: {
	        maxlength: {
	            immediate: true,
	            handler: function(newV) {
	                if (newV === 6) {
	                    this.ranges = [1, 2, 3, 4, 5, 6]
	                } else {
	                    this.ranges = [1, 2, 3, 4]
	                }
	            }
	        }
	    },
	    data() {
	        return {
				isShowStep:'',//传递给父组件
				countdown:'发送验证码',
				timeStatus:false,
				disabled:false ,//重新获取按钮是否开启
				navConfig: {
					comScroll:0,
					isFixed:false, //是否absolute布局
					left: {
				
						isShowLeft: true,
						leftGobackColor: 'black', //左边返回icon颜色
					},
					mid: {
						isShowMid: true,
						text: '',
						textColor: '#000'
					},
					right: {
						text: '',
						isShowRight: false,
						ico: '', //右侧图标地址
						isShowRightIco: '' //是否显示右侧图标
					}
				},
	            codeIndex: 1,
	            codeArr: [],
	            ranges: [1, 2, 3, 4]
	        }
	    },
	    methods: {
	        getVal(e) {
	            let { value } = e.detail
	            let arr = value.split('')
	            this.codeIndex = arr.length + 1
	            this.codeArr = arr
	            if (this.codeIndex > Number(this.maxlength)) {
	                this.$emit('finish',this.codeArr.join(''))
					console.log(1)
					uni.navigateTo({
						url: "spotOrder"
					})
	            }
	        },
			modalTap: function (e) {
				uni.showModal({
					title: "收不到验证码",
					content:"1、请确认当前手机是否使用预留手机号码。2、请查看短信是否被安全软件拦截。3、若预留号码已停用，请联系银行客服咨询 95533 4、获取更多帮助，可联系腾讯客服 95017",
					showCancel: false,
					confirmText: "知道了"
				})
			},
			// 验证码
			TimeBtn(){
				this.countdown = 60;
				this.timeStatus = true;
				let timer = setInterval(()=>{
					--this.countdown
				},1000)
				setTimeout(()=>{
					clearInterval(timer);
					this.timeStatus = false;
					this.countdown = '发送验证码';
				},60000);
				if(this.countdown == '发送验证码'){
					this.disabled = false
				}else{
					this.disabled = true
				}
			},
			toast1Tap: function () {
				window.history.go(-3); // 返回上两页
				uni.showToast({
					title: "绑定成功"
				})
			},
	    },
		// 自动触发
		// onShow(){
		// 	this.TimeBtn();
		// }
	}
	
</script>


<style scoped>
    @keyframes twinkling {
        0% {
            opacity: 0.2;
        }
        50% {
            opacity: 0.5;
        }
        100% {
            opacity: 0.2;
        }
    }
    .code-box {
		font-size: 30upx;
    }
    .flex-box {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        position: relative;
		margin-top:60upx;
    }
    .flex-box .hide-input {
        position: absolute;
        top: 0;
        left: -100%;
        width: 200%;
        height: 100%;
        text-align: left;
        z-index: 9;
        opacity: 1;
    }
    .flex-box .item {
        position: relative;
        width: 100upx;
        height: 100upx;
        margin-right: 45upx;
        font-size: 70upx;
        font-weight: bold;
        color: #333333;
        line-height: 100upx;
    }
    .flex-box .item:last-child {
        margin-right: 0;
    }
    .flex-box .middle {
        border: none;
    }
    .flex-box .box {
        box-sizing: border-box;
        border: 2upx solid #cccccc;
        border-radius: 6rpx;
    }
    .flex-box .bottom {
        box-sizing: border-box;
        border-bottom: 8rpx solid #212121;
    }
    .flex-box .active {
        border-color: #00C777;
    }
    .flex-box .active .line {
        display: block;
    }
    .flex-box .line {
        display: none;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 2upx;
        height: 40upx;
        background: #333333;
        animation: twinkling 1s infinite ease;
    }
    .flex-box .dot{
        font-size: 80upx;
        line-height: 40upx;
    }
    .flex-box .bottom-line {
        height: 4px;
        background: #000000;
        width: 80%;
        position: absolute;
        border-radius: 2px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
	.title{
		margin-top: 218upx;
		margin-left: 57upx;
		font-size: 40upx;
		font-family: PingFang SC Regular;
		font-weight: bold;
		color: rgba(51,51,51,1);
	}
	.YZM{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	.order-input{
		margin-left: 58upx;
		margin-top: 92upx;
	}
	.line{
		width: 428upx;
		height: 1upx;
		opacity: 1;
		background: rgba(220,220,220,1);
		margin-left: 49upx;
		margin-top: 26upx;
	}
	.mintuesBox{
		width:250upx;
		height: 150upx;
		clear: both;
		overflow: hidden;
		margin-right: 50upx;
	}
	.minuts{
		font-size:28upx;
		background: #559DFF;
		margin-top:84upx;
		float: right;
		/* margin-right: 50upx; */
	}
	.minuts:after{
		border:none !important;
	}
	.blueMintues{
		color: #FFFFFF !important;
	}
	.dlInput_psd input{
		width:570upx;
		height:46upx;
		line-height:46upx;
		margin-top:68upx;
		border-bottom: 1upx solid #DCDCDC;
		color: #333;
	}
	.regPsd .dlTit{
		font-size: 36upx;
		color: #333333;
		font-weight: bold;
	}
	.receive{
		margin-left: 59upx;
		margin-top: 35upx;
		font-size: 24upx;
		color: #549EFF;
	}
	.btn{
		width: 612upx;
		height: 80upx;
		margin-top: 134upx;
		margin-left: 69upx;
		border-radius: 50upx;
		background-image: linear-gradient(to right, #54B0FF, #5773FE);
		filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#5773FE', endColorstr='#54B0FF', GradientType=1);
	}
	.btn text{
		font-size: 28upx;
		font-family: PingFang SC Regular;
		color: #FFFFFF;
		margin-left: 278upx;
		margin-top: 20upx;
		position: absolute;
	}
</style>